Zooming and panning
Zooming and panning change the visible range of the axes: the user zooms with the mouse wheel or a pinch, and pans
by dragging the chart. Both features only move the MinLimit and MaxLimit of the axes, so the same range can also
be set from code, to show the data page by page or to drive the chart from a scroll bar. For axis limits in general,
see the axes article.
This article highlights the most used features. Every option is listed in the API explorer:
ZoomAndPanMode,
Axis and
CartesianChartEngine.
In XAML, declare the axes as XamlAxis.
Enable zooming
Zooming and panning are disabled by default. Set the ZoomMode property of the chart to enable them. With X, the
user zooms and pans only the X axis, and the Y axis fits the points that are visible in the current X range.
<lvc:CartesianChart
Series="{Binding Series}"
ZoomMode="X"> <!-- mark -->
</lvc:CartesianChart>

<UserControl
x:Class="WPFSample.Lines.Zoom.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"
xmlns:vms="clr-namespace:ViewModelsSamples.Lines.Zoom;assembly=ViewModelsSamples">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<lvc:CartesianChart
ZoomMode="X"> <!-- mark -->
<lvc:CartesianChart.Series>
<lvc:SeriesCollection>
<lvc:XamlLineSeries Values="{Binding Values}"/>
</lvc:SeriesCollection>
</lvc:CartesianChart.Series>
</lvc:CartesianChart>
</UserControl>
using System;
namespace ViewModelsSamples.Lines.Zoom;
public class ViewModel
{
public int[] Values { get; set; } = Fetch();
private static int[] Fetch()
{
var values = new int[100];
var r = new Random();
var t = 0;
for (var i = 0; i < 100; i++)
{
t += r.Next(-90, 100);
values[i] = t;
}
return values;
}
}
To change the default of every chart in the application, call
LiveCharts.Configure(config => config.WithZoomMode(ZoomAndPanMode.X)) when the application starts, before any chart
is created.
Zoom modes
ZoomMode is a ZoomAndPanMode flag
enum, so the options can be combined:
None: zooming and panning are disabled, the default.PanXandPanY: the user can pan the X or the Y axis.ZoomXandZoomY: the user can zoom the X or the Y axis, with the wheel, a pinch or a section.X: zoom and pan on the X axis, the same asPanX | ZoomX.Y: zoom and pan on the Y axis, the same asPanY | ZoomY.Both: zoom and pan on both axes, the same asX | Y.NoFit: lets the user move past the data, see fit to data.NoZoomBySection: disables the zoom by section.InvertPanningPointerTrigger: swaps the triggers of panning and zoom by section, see mouse and touch.
The last three flags only change the behaviour of the zoom and pan flags they are combined with.
Each gesture has its own flag, so they can be mixed: ZoomAndPanMode.ZoomX | ZoomAndPanMode.PanY zooms the X axis and
pans the Y axis, and ZoomAndPanMode.ZoomX zooms the X axis with no panning at all. Panning closes the tooltip while
the pointer drags, so a zoom-only mode keeps tooltips working when the user drags a finger over the chart on a touch
screen.
<lvc:CartesianChart ZoomMode="Both,NoFit"> <!-- mark -->
</lvc:CartesianChart>
With Y the user moves only the Y axis, and the X axis fits the points visible in the current Y range. With Both
the user moves both axes; it is easy to get lost in the data, so consider a button that
clears the zoom.

Mouse and touch
| Action | Mouse | Touch |
|---|---|---|
| Zoom | Mouse wheel | Pinch |
| Pan | Press the left button and drag | Press and drag |
| Zoom by section | Press the right button and drag | Double tap, keep the finger down on the second tap, drag |
The wheel zooms around the pointer: the value under the pointer stays in place.
This control does not handle the pinch gesture, use the mouse wheel to zoom.
When ZoomMode has the InvertPanningPointerTrigger flag, the triggers swap: the right button (or a double tap) pans,
and the left button (or a single tap) starts a zoom by section.
Zoom by section
The user can draw a rectangle over the chart and zoom to it. The feature is enabled with zooming, add the
NoZoomBySection flag to disable it. The section must start inside the plot area, and a drag shorter than 15 pixels
is ignored. When only one axis zooms, the rectangle covers the full height (or width) of the plot area, and only that
axis changes. The rectangle is drawn with a semi-transparent blue fill.

Zooming speed
ZoomingSpeed sets how much each step of the mouse wheel zooms, from 0 (slowest) to 1 (fastest). It is not the
speed of the animations. Each step in makes the visible range 1 - ZoomingSpeed times its length, each step out
divides the length by the same amount. The default is 0.2, so each step in shows 80% of the previous range. Values
under 0.1 work as 0.1 and values over 0.95 work as 0.95. The pinch gesture does not use this property.
<lvc:CartesianChart
Series="{Binding Series}"
ZoomMode="X"
ZoomingSpeed="0.1"> <!-- mark -->
</lvc:CartesianChart>
LiveCharts.Configure(config => config.WithZoomSpeed(0.1)) changes the default for every chart.
Fit to data
By default the chart keeps the data in view:
- Zooming out stops at the bounds of the data.
- Panning can go past the first or last point by the axis
BouncingDistance, a fraction of the plot area width (X axes) or height (Y axes). The default is0.25, a quarter of the plot area. When the pointer is released, the axis goes back to the data. SetBouncingDistanceto0to stop panning at the data.
Add the NoFit flag to let the user zoom and pan freely, past the data:

Minimum zoom
The axis MinZoomDelta property limits how deep the user can zoom: it is the smallest visible range the zoom can
reach, in data units (MaxLimit - MinLimit). Zooming in stops there, with the wheel, a pinch or a section. When it is
null, the default, the chart uses three times the smallest distance between two consecutive points of the data.
XAxes = new[]
{
new Axis
{
MinZoomDelta = 5 // the visible range is never shorter than 5 units // mark
}
};
Clearing the zoom
Set MinLimit and MaxLimit back to null (or double.NaN) to clear the zoom and fit the data to the chart again:
// where myChart is a reference to the chart in the UI
foreach (var x in myChart.XAxes)
{
x.MinLimit = null;
x.MaxLimit = null;
}
foreach (var y in myChart.YAxes)
{
y.MinLimit = null;
y.MaxLimit = null;
}
When the limits are bound to double properties of a view model, set the properties to double.NaN, as the
paging sample does.
Reading the visible range
While the user zooms or pans, the chart sets the MinLimit and MaxLimit of the axes. The Axis class implements
INotifyPropertyChanged, so the PropertyChanged event tells when the visible range changes, by the user or by code:
// where myChart is a reference to the chart in the UI
myChart.XAxes.First().PropertyChanged += OnAxisPropertyChanged;
// ...
private void OnAxisPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is not (nameof(Axis.MinLimit) or nameof(Axis.MaxLimit))) return;
var axis = (ICartesianAxis)sender!;
Trace.WriteLine($"{axis.Orientation} visible range: {axis.MinLimit} - {axis.MaxLimit}");
}
Paging
To show the data a page at a time, set MinLimit and MaxLimit from code. In this sample, the buttons move the X
axis by pages of eleven columns, and "Clear" shows all the data again. Each column is centered on its index, so
-0.5 to 10.5 shows the columns 0 to 10 completely. ZoomMode is X, so the user can still zoom and pan from
any page.

<UserControl
x:Class="WPFSample.Axes.Paging.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"
xmlns:vms="clr-namespace:ViewModelsSamples.Axes.Paging;assembly=ViewModelsSamples">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button Command="{Binding GoToPage1Command}">Page 1</Button>
<Button Command="{Binding GoToPage2Command}">Page 2</Button>
<Button Command="{Binding GoToPage3Command}">Page 3</Button>
<Button Command="{Binding SeeAllCommand}">Clear</Button>
</StackPanel>
<lvc:CartesianChart
Grid.Row="1"
ZoomMode="X">
<lvc:CartesianChart.Series>
<lvc:SeriesCollection>
<lvc:XamlColumnSeries Values="{Binding Values}"/>
</lvc:SeriesCollection>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.XAxes>
<lvc:AxesCollection>
<lvc:XamlAxis
MinLimit="{Binding MinLimit}"
MaxLimit="{Binding MaxLimit}"/>
</lvc:AxesCollection>
</lvc:CartesianChart.XAxes>
</lvc:CartesianChart>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace ViewModelsSamples.Axes.Paging;
public partial class ViewModel : ObservableObject
{
public int[] Values { get; set; } = Fetch();
[ObservableProperty]
public partial double MinLimit { get; set; } = double.NaN;
[ObservableProperty]
public partial double MaxLimit { get; set; } = double.NaN;
[RelayCommand]
public void GoToPage1()
{
MinLimit = -0.5;
MaxLimit = 10.5;
}
[RelayCommand]
public void GoToPage2()
{
MinLimit = 9.5;
MaxLimit = 20.5;
}
[RelayCommand]
public void GoToPage3()
{
MinLimit = 19.5;
MaxLimit = 30.5;
}
[RelayCommand]
public void SeeAll()
{
MinLimit = double.NaN;
MaxLimit = double.NaN;
}
private static int[] Fetch()
{
var random = new Random();
var trend = 100;
var values = new List<int>();
for (var i = 0; i < 100; i++)
{
trend += random.Next(-30, 50);
values.Add(trend);
}
return [.. values];
}
}
Scrollable chart
A second, smaller chart can work as a scroll bar. In this sample the main chart has ZoomMode set to X. Below it,
a chart 100 pixels tall plots the same data with hidden axes and no tooltips, and a RectangularSection marks the
range visible in the main chart. Both charts set the same left and right DrawMargin, so their plot areas line up.
The sync goes both ways:
- When the main chart updates (after a zoom or a pan), its
UpdateStartedevent copies the X axis limits to theXiandXjof the section. - While the pointer is pressed on the small chart, each move converts the pointer position to data coordinates with
ScalePixelsToData, centers the section there keeping its width, and sets the same range as theMinLimitandMaxLimitof the main chart's X axis.

<UserControl
x:Class="WPFSample.General.Scrollable.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"
xmlns:vms="clr-namespace:ViewModelsSamples.General.Scrollable;assembly=ViewModelsSamples">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<!--
We use the DrawMargin property to align both charts,
both charts have a left margin of 100 and a right margin of 50
-->
<lvc:CartesianChart
Grid.Row="0"
DrawMargin="100, Auto, 50, Auto"
ZoomMode="X"
UpdateStartedCommand="{Binding ChartUpdatedCommand}">
<lvc:CartesianChart.Series>
<lvc:SeriesCollection>
<lvc:XamlLineSeries
Values="{Binding Values}"
GeometryStroke="{x:Null}"
GeometryFill="{x:Null}"
DataPadding="0,1"/>
</lvc:SeriesCollection>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.XAxes>
<lvc:AxesCollection>
<lvc:XamlAxis
MinLimit="{Binding MinX}"
MaxLimit="{Binding MaxX}" />
</lvc:AxesCollection>
</lvc:CartesianChart.XAxes>
</lvc:CartesianChart>
<lvc:CartesianChart
Grid.Row="1"
DrawMargin="100, Auto, 50, Auto"
PointerPressedCommand="{Binding PointerDownCommand}"
PointerMoveCommand="{Binding PointerMoveCommand}"
PointerReleasedCommand="{Binding PointerUpCommand}"
TooltipPosition="Hidden">
<lvc:CartesianChart.Series>
<lvc:SeriesCollection>
<lvc:XamlLineSeries
Values="{Binding Values}"
GeometryStroke="{x:Null}"
GeometryFill="{x:Null}"
DataPadding="0,1"/>
</lvc:SeriesCollection>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.XAxes>
<lvc:AxesCollection>
<lvc:XamlAxis IsVisible="False"/>
</lvc:AxesCollection>
</lvc:CartesianChart.XAxes>
<lvc:CartesianChart.YAxes>
<lvc:AxesCollection>
<lvc:XamlAxis IsVisible="False"/>
</lvc:AxesCollection>
</lvc:CartesianChart.YAxes>
<lvc:CartesianChart.Sections>
<lvc:SectionsCollection>
<lvc:XamlRectangularSection
Xi="{Binding MinXThumb}"
Xj="{Binding MaxXThumb}"
Fill="{lvc:SolidColorPaint Color='#64FFCDD2'}"/>
</lvc:SectionsCollection>
</lvc:CartesianChart.Sections>
</lvc:CartesianChart>
</Grid>
</UserControl>
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using LiveChartsCore;
using LiveChartsCore.Defaults;
using LiveChartsCore.Kernel.Events;
using LiveChartsCore.Kernel.Sketches;
namespace ViewModelsSamples.General.Scrollable;
public partial class ViewModel : ObservableObject
{
private static double _defaultMin = 0;
private static double _defaultMax = 100;
private bool _isDown = false;
public ObservablePoint[] Values { get; } = Fetch();
[ObservableProperty]
public partial double MinX { get; set; } = _defaultMin;
[ObservableProperty]
public partial double MaxX { get; set; } = _defaultMax;
[ObservableProperty]
public partial double MinXThumb { get; set; } = _defaultMin;
[ObservableProperty]
public partial double MaxXThumb { get; set; } = _defaultMax;
[RelayCommand]
public void ChartUpdated(ChartCommandArgs args)
{
var cartesianChart = (CartesianChartEngine)args.Chart.CoreChart;
var x = cartesianChart.XAxes.First();
// when the main chart is updated, we need to update the scroll bar thumb limits
// this will sync the scroll bar with the main chart when the user is zooming or panning
MinXThumb = x.MinLimit ?? _defaultMin;
MaxXThumb = x.MaxLimit ?? _defaultMax;
}
[RelayCommand]
public void PointerDown(PointerCommandArgs args) =>
_isDown = true;
[RelayCommand]
public void PointerMove(PointerCommandArgs args)
{
if (!_isDown) return;
var chart = (ICartesianChartView)args.Chart;
var positionInData = chart.ScalePixelsToData(args.PointerPosition);
var currentRange = MaxXThumb - MinXThumb;
var min = positionInData.X - currentRange / 2;
var max = positionInData.X + currentRange / 2;
// optional, use the data bounds as limits for the thumb
if (min < Values[0].X)
{
min = Values[0].X ?? _defaultMin;
max = min + currentRange;
}
if (max > Values[^1].X)
{
max = Values[^1].X ?? _defaultMax;
min = max - currentRange;
}
// update the scroll bar thumb when the user is dragging the chart
MinXThumb = min;
MaxXThumb = max;
// update the chart visible range
MinX = min;
MaxX = max;
}
[RelayCommand]
public void PointerUp(PointerCommandArgs args) =>
_isDown = false;
private static ObservablePoint[] Fetch()
{
var trend = 1000;
var r = new Random();
var values = new ObservablePoint[500];
for (var i = 0; i < 500; i++)
values[i] = new ObservablePoint(i, trend += r.Next(-20, 20));
return values;
}
}
Zoom and pan from code
The chart engine has the methods that the gestures call. They take the flags to apply, so they work even when
ZoomMode is None, for example to zoom with buttons or with your own gestures. Positions and distances are in pixels.
// where myChart is a reference to the chart in the UI
var engine = (CartesianChartEngine)myChart.CoreChart;
// zooms in on the X axis, keeping the value at the pixel (100, 100) in place
engine.Zoom(ZoomAndPanMode.X, new(100, 100), ZoomDirection.ZoomIn);
// pans both axes by 10 pixels
engine.Pan(ZoomAndPanMode.Both, new(10, 10));
// zoom by section: starts the rectangle at (100, 100),
engine.StartZoomingSection(ZoomAndPanMode.Both, new(100, 100));
// grows the drawn rectangle to (150, 150), the zoom is not applied yet,
engine.GrowZoomingSection(ZoomAndPanMode.Both, new(150, 150));
// and zooms to the rectangle that ends at (200, 200)
engine.EndZoomingSection(ZoomAndPanMode.Both, new(200, 200));
Zoom honours the NoFit flag it receives: without it, the zoom is fitted to the data, as the wheel does.